package leetcode;

import java.sql.SQLOutput;
import java.util.HashMap;
import java.util.Map;

public class DigitCount {
    public static void main(String[] args) {
        DigitCount digitCount = new DigitCount();
        System.out.println(digitCount.digitCount("030"));
    }

    public boolean digitCount(String num) {
        Map<Integer, Integer> map = new HashMap<>();
        char[] nums = num.toCharArray();
        for (char n : nums) {
            Integer key = Integer.parseInt(String.valueOf(n));
            if (map.containsKey(key)) {
                map.put(key, map.get(key) + 1);
            } else {
                map.put(key, 1);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (Integer.parseInt(String.valueOf(nums[i])) != map.getOrDefault(i, 0)) {
                return false;
            }
        }
        return true;
    }
}
